<?php
	error_reporting(E_ALL^E_NOTICE);
	require_once ('../config/config.php'); 
	require_once ('../class/email.class.php'); 
	require_once ('../class/tools.class.php');
	date_default_timezone_set("PRC");
	session_start();
	$b= mysqli_fetch_assoc(mysqli_query($con,"select count(*) as AllNum from master"));
	if($b['AllNum']!=0){
		echo "<script>location='./login.php';</script>";
		exit();
	}
	if(!empty($_SESSION['admin'])){
		echo "<script>location='./index.php';</script>";
		exit();
	}else{
		if($_POST){
			$user=$_POST['user'];
			$pwd=sha1($_POST['pwd']);
			$repwd=sha1($_POST['repwd']);
			if(empty($user) or empty($pwd) or empty($repwd)){
				echo "<script>alert('请输入完整信息！');location='./install.php';</script>";
				exit();
			}else{
				if($pwd==$repwd){

				}else{
					echo "<script>alert('两次密码输入不一致，请检查后重试！');location='./install.php';</script>";
					exit();
				}
				mysqli_query($con,"INSERT INTO `master` (`mid`, `user`, `password`, `type`, `state`) VALUES (NULL, '".$user."', '".$pwd."', '1', '1')");
				echo "<script>alert('安装完成，即将跳转到后台登陆界面！');location='./login.php';</script>";
				exit();
			}
		}
	}
?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>后台安装</title>
<link rel="stylesheet" type="text/css" href="css/login.css">
</head>
<body>
	<div id="wrapper" class="login-page">
		<div id="login_form" class="form">
			<form class="login-form" action="./install.php" method="post">
				<h2>请设置超级管理员信息</h2>
				<input type="text" placeholder="请输入管理员账号" name="user" id="user_name" />
				<input type="password" placeholder="请输入管理员密码" name="pwd" id="password" />
				<input type="password" placeholder="请再次输入管理员密码" name="repwd" id="password" />
				<button type="submit" id="login">完成安装</button>
			</form>
		</div>
	</div>
<script src="js/jquery.min.js"></script>
</body>
</html>